class House < ActiveRecord::Base
	validates_presence_of :name, :abbrev, :address, :phone
	validates_uniqueness_of :name, :abbrev
	
	has_many :jaunts
	has_many :overnights
	has_many :users
	has_many :house_visits
	has_many :favorite_freshmen, :order => :position
	has_many :checks, :through => :users
	
	def active_jaunts
	  all_jaunts = jaunts.find(:all)
	  current_active_jaunts =all_jaunts.find_all { |this_jaunt|
	    this_jaunt.currently_active
	  }
	  return current_active_jaunts
	end
	
	def overnighting_freshmen
	  all_overnights=overnights.find(:all)
	  current_overnighting_freshmen = all_overnights.collect { |this_overnight|
	    if (this_overnight.currently_active)
	      this_overnight.freshman
	    else
	      nil
	    end
	  }
	  return current_overnighting_freshmen.compact
	end
	
	def freshmen_in_house
	  all_house_visits=house_visits.find(:all)
	  current_visiting_freshmen = all_house_visits.collect { |this_house_visit|
	    if (this_house_visit.currently_active and this_house_visit.freshman.current_jaunt.nil? and this_house_visit.freshman.current_overnight.nil?)
	      this_house_visit.freshman
	    else
	      nil
	    end
	  }
	  return current_visiting_freshmen.compact
	end
end
